home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 4 / Apprentice-Release4.iso / Source Code / Pascal / Snippets / Fixed Point Conversions / NoCoprocessorMath.p < prev    next >
Encoding:
Text File  |  1995-11-13  |  2.2 KB  |  86 lines  |  [TEXT/PJMM]

  1. (**********************************************************************************)
  2. (* Unit to perform math functions when no coprocessor is available.               *)
  3. (* Last modified: 1995-11-12                                                      *)
  4. (*                                                                                *)
  5. (* send comments & suggestions to:                                                *)
  6. (* Daniel W. Rickey                                                               *)
  7. (* Department of Medical Physics                                                  *)
  8. (* Manitoba Cancer Treatment and Research Foundation                              *)
  9. (* 100 Olivia Street                                                              *)
  10. (* Winnipeg, Manitoba                                                             *)
  11. (* R3E 0V9 CANADA                                                                 *)
  12. (* daniel@kaon.mctrf.mb.ca  or physics@escape.ca                                  *)
  13. (**********************************************************************************)
  14. Unit NoCoprocessorMath;
  15.  
  16. Interface
  17.  (* performs arcsine *)
  18.     Function aSin (x: double): double;
  19.  
  20.  (* performs arccosine *)
  21.     Function aCos (x: double): double;
  22.  
  23.  (* two to the power of X *)
  24.     Function Exp2 (x: double): double;
  25.  
  26. Implementation
  27.     Const
  28.         Pi = 3.141592654;
  29.  
  30.  
  31.  (**** two to the power of X ****)
  32.     Function Exp2 (x: double): Double;
  33.         Const
  34.             kln2 = 0.69314718;
  35.  
  36.     Begin
  37.     Exp2 := Exp(kln2 * x);
  38.     End;  {Exp2}
  39.  
  40.  
  41.  (**** performs arccosine ****)
  42.     Function aCos (x: double): double;
  43.     Begin
  44.  {do a range check in case x = ±1.0000001}
  45.     If x > 1 Then
  46.         aCos := 0
  47.     Else If x < -1 Then
  48.         aCos := Pi
  49.     Else
  50.         aCos := (2 * ArcTan(SQRT((1 - x) / (1 + x))));
  51.     End;  {aCos}
  52.  
  53.  
  54.  (**** performs arcsine ****)
  55.     Function aSin (x: double): double;
  56.         Var
  57.             y: Double;
  58.  
  59.     Begin
  60.  {do a range check in case x = ±1.0000001}
  61.     If x > 1.0 Then
  62.         Begin
  63.         aSin := Pi / 2;
  64.         Exit(aSin);
  65.         End
  66.     Else If x < -1.0 Then
  67.         Begin
  68.         aSin := -Pi / 2;
  69.         Exit(aSin);
  70.         End;
  71.  
  72.     y := Abs(x);
  73.  
  74.     If (y > 0.5) Then
  75.         Begin
  76.         y := 1 - y;
  77.         y := 2 * y - y * y;
  78.         End
  79.     Else
  80.         Begin
  81.         y := 1 - y * y;
  82.         End;
  83.     aSin := (ArcTan(x / SQRT(y)));
  84.     End;  {aSin}
  85.  
  86. End.